/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class code4 {
    //验证二叉搜索树:中序遍历是有序的
    public Long prev = Long.MIN_VALUE;//防止root就是Integer.MIN_VALUE
    public boolean isValidBST(TreeNode root) {
        //递归出口
        if(root==null) return true;

        //左
        boolean Left = isValidBST(root.left);
        //剪枝
        if(Left == false) return false;

        //中
        boolean Root = false;
        if(root.val>prev) {
            Root = true;
            prev = (long)root.val;
        }
        //剪枝
        else return false;

        //右
        return isValidBST(root.right);

    }
}